﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.Reflection;

namespace ObjectBakery.Helpers
{
    public class FileSystemHelper
    {
        public FileInfo GetTempFile()
        {
            string path = Path.GetTempPath();
            string fileName = Guid.NewGuid().ToString();
            string fullName = path + fileName;
            using (FileStream fs = File.Create(fullName)) { }
            return new FileInfo(fullName);
        }

        public DirectoryInfo GetEnsuredDirectory(string path)
        {
            DirectoryInfo di;
            if (!Directory.Exists(path))
                di = Directory.CreateDirectory(path);
            else
                di = new DirectoryInfo(path);
            return di;
        }

        public DirectoryInfo ExecutingDirectory
        {
            get
            {
                return new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
            }
        }

        public DirectoryInfo GetTypeAssemblyDirectory(Type t)
        {
                return new DirectoryInfo(Path.GetDirectoryName(t.Assembly.Location));
        }
    }
}
